const express = require('express');
const multer = require('multer');
const app = express();

// 设置存储配置
const storage = multer.diskStorage({
    destination: function (req, file, cb) {
        cb(null, 'uploads/') // 确保这个文件夹已经存在
    },
    filename: function (req, file, cb) {
        cb(null, file.fieldname + '-' + Date.now())
    }
})

const upload = multer({ storage: storage, array: 'photos' })

app.post('/upload', upload.array('photos', 12), function (req, res, next) {
    // req.files 是 'photos' 文件数组
    // 文件信息存储在 req.files
    res.send('File uploaded successfully.')
})

app.listen(3000, () => {
    console.log('Server is running on port 3000');
});